package com.atguigu.gulimall.product.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * @ClassName MyRedissonConfig
 * @Description TODO
 * @Author 13290
 * @Date 2022/10/4 11:01
 **/
@Configuration
public class MyRedissonConfig {

    /**
     * @author
     * @Description 所有对redisson的操作  都要通过RedissonClient
     * @Date 11:03 2022/10/4
     * @param
     * @Return org.redisson.api.RedissonClient
     **/
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redisson() throws IOException {
        //创建配置
        Config config = new Config();
        //集群模式
        //config.useClusterServers().addNodeAddress("127.0.0.1:7004","127.0.0.1:7001");
        //单节点模式
        config.useSingleServer().setAddress("redis://127.0.0.1:6379");
        //根据config创建出redisson 实例
        return Redisson.create(config);
    }

}
